<?php

/**
 * Adding a GotProRole
 * @package ModuleOrganisationCommunication
 * @version 1.0b
 */

session_start();

// Configuration file
include '../configuration.php';
// Functions
include '../inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	exit();
endif;

// Include all objects
// TODO: Include only needed classes
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

try {
	// Format purposes
	$dateFrom = explode('/', $_POST['from']);
	$dateFrom = $dateFrom[2].'-'.$dateFrom[1].'-'.$dateFrom[0];
	$dateTo = explode('/', $_POST['to']);
	$dateTo = $dateTo[2].'-'.$dateTo[1].'-'.$dateTo[0];
	
	// Creating gotProRole
	$gotprorole = new GotProRole();
	$gotprorole->companyId = $_POST['company'];
	$gotprorole->contactId = $_POST['contact'];
	$gotprorole->from = $dateFrom;
	$gotprorole->to = $dateTo;
	$gotprorole->proroleId = $_POST['prorole'];
	
	// Inserting gotProRole into database
	$gotprorole->SaveNew();
	
	echo 'OK';

} catch (Exception $e) {
	echo $e->getMessage();
}
?>